home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / intuition / drawborder.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  141 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: drawborder.c,v 1.2 1996/08/29 13:33:30 digulla Exp $
  4.     $Log: drawborder.c,v $
  5.     Revision 1.2  1996/08/29 13:33:30  digulla
  6.     Moved common code from driver to Intuition
  7.     More docs
  8.  
  9.     Revision 1.1  1996/08/23 17:28:18  digulla
  10.     Several new functions; some still empty.
  11.  
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include "intuition_intern.h"
  17. #include <clib/graphics_protos.h>
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <graphics/rastport.h>
  23.     #include <intuition/intuition.h>
  24.     #include <clib/intuition_protos.h>
  25.  
  26.     __AROS_LH4(void, DrawBorder,
  27.  
  28. /*  SYNOPSIS */
  29.     __AROS_LHA(struct RastPort *, rp, A0),
  30.     __AROS_LHA(struct Border   *, border, A1),
  31.     __AROS_LHA(long             , leftOffset, D0),
  32.     __AROS_LHA(long             , topOffset, D1),
  33.  
  34. /*  LOCATION */
  35.     struct IntuitionBase *, IntuitionBase, 18, Intuition)
  36.  
  37. /*  FUNCTION
  38.     Draws one or more borders in the specified RastPort. Rendering
  39.     will start at the position which you get when you add the offsets
  40.     leftOffset and topOffset to the LeftEdge and TopEdge specified
  41.     in the Border structure. All subsequent adresses in the Border
  42.     structure are relative to the previous position.
  43.  
  44.     INPUTS
  45.     rp - The RastPort to render into
  46.     border - Information what and how to render
  47.     leftOffset, topOffset - Initial starting position
  48.  
  49.     RESULT
  50.     None.
  51.  
  52.     NOTES
  53.  
  54.     EXAMPLE
  55.     // Draw a house with one stroke
  56.     WORD XY[] =
  57.     {
  58.         +10, +10,
  59.         -10,   0,    // Top
  60.         +10, -10,
  61.         -10,   0,    // Bottom
  62.           0, -10,    // Left
  63.          +5,  +5,    // Roof
  64.          +5,  -5,
  65.           0, +10    // Right
  66.     };
  67.     struct Border demo =
  68.     {
  69.         100, 100,    // Position
  70.         1, 2,    // Pens
  71.         JAM1,    // Drawmode
  72.         8,        // Number of pairs in XY
  73.         XY,     // Vector offsets
  74.         NULL    // No next border
  75.     };
  76.  
  77.     // Render the house with the bottom left edge at 150, 50
  78.     DrawBorder (rp, &demo, 50, -50);
  79.  
  80.     BUGS
  81.  
  82.     SEE ALSO
  83.  
  84.     INTERNALS
  85.  
  86.     HISTORY
  87.     29-10-95    digulla automatically created from
  88.                 intuition_lib.fd and clib/intuition_protos.h
  89.  
  90. *****************************************************************************/
  91. {
  92.     __AROS_FUNC_INIT
  93.     __AROS_BASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  94.     ULONG  apen;
  95.     ULONG  bpen;
  96.     ULONG  drmd;
  97.     WORD * ptr;
  98.     WORD   x, y;
  99.     int    t;
  100.  
  101.     /* Store important variables of the RastPort */
  102.     apen = GetAPen (rp);
  103.     bpen = GetBPen (rp);
  104.     drmd = GetDrMd (rp);
  105.  
  106.     /* For all borders... */
  107.     for ( ; border; border=border->NextBorder)
  108.     {
  109.     /* Change RastPort to the colors/mode specified */
  110.     SetAPen (rp, border->FrontPen);
  111.     SetBPen (rp, border->BackPen);
  112.     SetDrMd (rp, border->DrawMode);
  113.  
  114.     /* Move to initial position */
  115.     Move (rp
  116.         , x = border->LeftEdge + leftOffset
  117.         , y = border->TopEdge + topOffset
  118.     );
  119.  
  120.     /* Start of vector offsets */
  121.     ptr = border->XY;
  122.  
  123.     for (t=0; t<border->Count; t++)
  124.     {
  125.         /* Add vector offset to current position */
  126.         x += *ptr ++;
  127.         y += *ptr ++;
  128.  
  129.         /* Stroke */
  130.         Draw (rp, x, y);
  131.     }
  132.     }
  133.  
  134.     /* Restore RastPort */
  135.     SetAPen (rp, apen);
  136.     SetBPen (rp, bpen);
  137.     SetDrMd (rp, drmd);
  138.  
  139.     __AROS_FUNC_EXIT
  140. } /* DrawBorder */
  141.